//js hhz 20181225



//通用弹出提示框
function showToast(msg) {
    console.log(msg);
    var tipsHtml = "<div class=\'tips-pop\' id=\'tipsPop\'>" + msg + "</div>"
    $("body").append(tipsHtml);
    setTimeout(() => {
        $("#tipsPop").fadeOut(800).remove();
    }, 1000);
}


// 滚动通知
// JavaScript Document
stcrollToHeight = 22;
function b() {
    //设置滚动高度
    t = parseInt(x.css('top'));
    y.css('top', stcrollToHeight + 'px');
    x.animate({ top: t - stcrollToHeight + 'px' }, 'slow');
    if (Math.abs(t) == h - stcrollToHeight) { //19为每个li的高度
        y.animate({ top: '0px' }, 'slow');
        z = x;
        x = y;
        y = z;
    }
    setTimeout(b, 3000);//滚动间隔时间 现在是3秒
}
$(document).ready(function () {
    $('.swap').html($('.news_li').html());
    x = $('.news_li');
    y = $('.swap');
    h = $('.news_li li').length * stcrollToHeight; //22为每个li的高度
    setTimeout(b, 300);//滚动间隔时间 现在是3秒

})


//文本超出处理
$(function () {
    var overTxtObj = $(".over-text")
    var overTxt = overTxtObj.html();
    var overTxtHeight = overTxtObj.height();
    var overTxtWidth = overTxtObj.width();
    overTxtObj.css({
        height: overTxtHeight,
        width: overTxtWidth
    });
    var overTxtCont = "<span id=\'newOverTxt\' style=\' position: absolute; left: 0px;\'>" + overTxt + "</span>"
     overTxtObj.html(overTxtCont);
    var newOverTxtWidth = $("#newOverTxt").width();
    var leftText = overTxtWidth - newOverTxtWidth;
    function getPositLeft(){
        var position = $("#newOverTxt").position();
        var txtLeft = position.left;
        if(txtLeft == 0){
            setTimeout(() => {
                $("#newOverTxt").css({
                    left: leftText
                });
                getPositLeft()
            }, 1000);
        }
        else if(txtLeft == txtLeft){
            setTimeout(() => {
                $("#newOverTxt").css({
                    left: 0
                });
                getPositLeft()
            }, 8000);
        }
        return txtLeft;
    };
    setInterval(getPositLeft(),8000);
})


//driversList高度自适应
$(function(){
    function setDriversListHeight(){
        var winHeight = $(window).innerHeight();
        var ListTilHeight = $("#ListTil").innerHeight();
        $("#driversList").height(winHeight-ListTilHeight - 379 );
    }
    setDriversListHeight();//初始化高度
    $(window).resize(function () { 
        setDriversListHeight();
    });
})

//driverListB高度自适应
$(function(){
    function setDriversListHeightB(){
        var winHeight = $(window).innerHeight();
        var currdTtheight = $("#currdTt").innerHeight();
        console.log(currdTtheight);
        $("#driverListB").height(winHeight-currdTtheight - 120 );
    }
    setDriversListHeightB();
    $(window).resize(function () { 
        setDriversListHeightB();
    });

})
//gzList高度设置
$(function(){
    function setdriverSearchListHeight(){
        var winHeight = $(window).innerHeight();
        var driverNavHeight = $("#driverNav").innerHeight();
        var dariverListPageHeight = $("#dariverListPage").innerHeight();
        var driverSearchHeight = $(".driver-search").innerHeight();
        $("#driverSearchList").height(winHeight-driverNavHeight - dariverListPageHeight - driverSearchHeight - 175 );
    }
    setdriverSearchListHeight();
    $(window).resize(function () { 
        setdriverSearchListHeight();
    });

})


//检查密码
$(function () {
    //鼠标按住方式检查密码
    $("#eyesWatch").mousedown(function () { 
        $(this).addClass("icon-chakanmima");
        $("#loginUserPwd").attr("type", "text")
    });
    $("#eyesWatch").mouseup(function () { 
        $(this).removeClass("icon-chakanmima");
        $("#loginUserPwd").attr("type", "password")
    });

    // 鼠标点击方式
    // $("#eyesWatch").click(function (e) {
    //     $(this).toggleClass("icon-chakanmima");
    //     if ($("#loginUserPwd").attr("type") == "password") {
    //         $("#loginUserPwd").attr("type", "text")
    //     }
    //     else {
    //         $("#loginUserPwd").attr("type", "password")
    //     }
    // });
});


//保存密码到cookie

//绑定checkbox
$(function(){
    $('#remeberPwdIcon').on('click', function () {
        $(this).toggleClass('checked-pwd');
        $('#remeberPwd').click();
    });
})
function saveCookies(){
    console.log("运行了saveCookies()");
    if($("#remeberPwd").prop("checked")){
        var username = $("#loginUsername").val();
        var password = $("#loginUserPwd").val();

        $.cookie("remember","true",{expires:7});
        $.cookie("username",username,{expires:7 });
        $.cookie("password",password,{expires:7 });
        console.log("保存了cookie");
    }else{
        $.cookie("remember","false",{expires:-1});
        $.cookie("username","",{ expires:-1 });
        $.cookie("password","",{ expires:-1 });
        console.log("清除了cookie");
    }
};
//加载密码from cookie
$(function(){
    var rem = $.cookie('remember');
    if(rem){
        $("#remeberPwd").prop("checked",true);
        $("#loginUsername").val($.cookie("username"));
        $("#loginUserPwd").val($.cookie("password"));
    }
    console.log(rem);
});

//登录提交
function loginSumbit(){
    var username = $("#loginUsername").val();
    var password = $("#loginUserPwd").val();
    if( username != '' && password != ''){
        saveCookies();
        //发起请求
    }
    else {
        showToast("输入不全")
    }
}

